function parseAndShowXML(text,topId,contentId,bottomId){
    var parser = new DOMParser();
    var xmlDoc = parser.parseFromString(text,"text/xml");
    var adv = xmlDoc.getElementsByTagName('adv')[0];
    // var title = adv.getAttribute('title');
    // if (title == null) {
    //     title = '广告详情';
    // }
    // document.title = title;
    for (var i = 0; i < adv.childElementCount; i++) {
        var node = adv.childNodes[i];
        if (node.nodeName == 'head') {
            if (node.childElementCount > 0) {
                var node = node.childNodes[0];
                if (node.nodeName == 'image') {
                    var element = _createImageElement(node);
                    var scene = document.getElementById(topId);
                    scene.appendChild(element);
                } else if (node.nodeName == 'video') {
                    var element = _createVideoElement(node);
                    var scene = document.getElementById(topId);
                    scene.appendChild(element);
                }else if (node.nodeName == 'title') {
                    var element =  _createTitleElement(node);
                    var scene = document.getElementById(topId);
                    scene.appendChild(element);
                }
            }
        } else if (node.nodeName == 'title') {
            _createTitleElement(node);
        } else if (node.nodeName == 'text') {
            _createTextElement(node);
        } else if (node.nodeName == 'image') {
            var element = _createImageElement(node);
            _appendSceneMarginDivWithElement(contentId, element);
        }  else if (node.nodeName == 'video') {
            var element = _createVideoElement(node);
            _appendSceneMarginDivWithElement(contentId, element);
        }
        function _createTitleElement(node) {
            var __sizeAttributes = node.getAttribute('font')
            var _sizeAttributes = [];
            if (__sizeAttributes != null) {
                _sizeAttributes = __sizeAttributes.split(',');
            }
            var _font = 25;
            if (_sizeAttributes.count > 0) {
                _font = _sizeAttributes[0]
            }
            var __styleAttributes = node.getAttribute('style');
            var _styleAttributes = [];
            if (__styleAttributes != null) {
                _styleAttributes = __sizeAttributes.split(',');
            }
            var _lineSpace = 9;
            if (_styleAttributes.count > 0) {
                _lineSpace = _styleAttributes[0];
            }
            var _paraSpace = 30;
            if (_styleAttributes.count > 1) {
                _paraSpace = _styleAttributes[1];
            }
            var _aligment = 'justify';
            if (_styleAttributes.count > 2) {
                if (_styleAttributes[2] == 'L') {
                    _aligment = 'left'
                } else if (_styleAttributes[2] == 'C') {
                    _aligment = 'center'
                } else if (_styleAttributes[2] == 'R') {
                    _aligment = 'right'
                }
            }
            var _color = node.getAttribute('color');
            if (_color == null) {
                _color = '#101010';
            }
            var style = '';
            style += 'font-size:' + _font + 'px;';
            style += 'color:' + _color + ';';
            style += 'line-height:' + (_font + _lineSpace) + 'px;';
            style += 'text-align:' + _aligment + ';';
            style += 'font-weight:bold;';

            var element = document.createElement("p");
            element.setAttribute('style', style);
            var text = document.createTextNode(node.textContent);
            element.appendChild(text);
            var scene = document.getElementById(contentId);
            scene.appendChild(element);
            return element;
        }
        function _createTextElement(node) {
            var __sizeAttributes = node.getAttribute('font')
            var _sizeAttributes = [];
            if (__sizeAttributes != null) {
                _sizeAttributes = __sizeAttributes.split(',');
            }
            var _font = 19;
            if (_sizeAttributes.count > 0) {
                _font = _sizeAttributes[0]
            }
            var _isBold = false;
            if (_sizeAttributes.count > 1) {
                if (_sizeAttributes[1] == 'B') {
                    _isBold = true;
                }
            }
            var __styleAttributes = node.getAttribute('style');
            var _styleAttributes = [];
            if (__styleAttributes != null) {
                _styleAttributes = __sizeAttributes.split(',');
            }
            var _lineSpace = 9;
            if (_styleAttributes.count > 0) {
                _lineSpace = _styleAttributes[0];
            }
            var _paraSpace = 30;
            if (_styleAttributes.count > 1) {
                _paraSpace = _styleAttributes[1];
            }
            var _aligment = 'justify';
            if (_styleAttributes.count > 2) {
                if (_styleAttributes[2] == 'L') {
                    _aligment = 'left'
                } else if (_styleAttributes[2] == 'C') {
                    _aligment = 'center'
                } else if (_styleAttributes[2] == 'R') {
                    _aligment = 'right'
                }
            }
            var _color = node.getAttribute('color');
            if (_color == null) {
                _color = '#878787';
            }
            var style = '';
            style += 'font-size:' + _font + 'px;';
            style += 'color:' + _color + ';';
            style += 'line-height:' + (_font + _lineSpace) + 'px;';
            if (_isBold) {
                style += 'font-weight:bold;';
            }
            style += 'text-align:' + _aligment;

            var element = document.createElement("p");
            element.setAttribute('style', style);
            var text = document.createTextNode(node.textContent);
            element.appendChild(text);
            var scene = document.getElementById(contentId);
            scene.appendChild(element);
            return element
        }
        function _createImageElement(node) {
            var _url = node.getAttribute('src');
            var _width = 300;
            var _height = 300 * 405 / 720;
            var __sizeAttributes = node.getAttribute('size');
            if (__sizeAttributes != null) {
                var arr = __sizeAttributes.split('x');
                if (arr.count > 1) {
                    var w = parseFloat(arr[0]);
                    var h = parseFloat(arr[1]);
                    if (w > 0 && h > 0) {
                        _height = _width * h / w;
                    }
                }
            }
            var element = document.createElement('img');
            element.setAttribute('src', _url);
            element.setAttribute('width', _width);
            element.setAttribute('height', _height);
            return element;
        }
        function _createVideoElement(node) {
            var _url = node.getAttribute('src');
            var __sizeAttributes = node.getAttribute('size');
            var _sizeAttributes = [];
            var _width = 300;
            var _height = 300 * 405 / 720;
            if (__sizeAttributes != null) {
                var arr = __sizeAttributes.split('x');
                if (arr.count > 1) {
                    var w = parseFloat(arr[0]);
                    var h = parseFloat(arr[1]);
                    if (w > 0 && h > 0) {
                        _height = _width * h / w;
                    }
                }
            }
            var _thumb = node.getAttribute('thumb');
            var element = document.createElement('video');
            element.setAttribute('src', _url);
            element.setAttribute('width', _width);
            // element.setAttribute('width', _width + 'vw');
            element.setAttribute('height', _height);
            element.setAttribute('controls', 'controls');
            element.setAttribute('poster', _thumb);
            element.setAttribute('style', 'background-color:black');
            element.setAttribute('preload', 'none');
            var text = document.createTextNode('浏览器不支持视频播放');
            element.appendChild(text);
            return element;
        }
        function _appendSceneMarginDivWithElement(scene, element) {
            var _width = 310;
            var _height = 310 * 405 / 720;
            var div = document.createElement('div');
            div.setAttribute('style', 'margin:30px 0px 30px 0px;width=310px;height=174.375px;');
            div.appendChild(element);
            var theScene = document.getElementById(scene);
            theScene.appendChild(div);
        }
    }
}